import Vue from 'vue'
import VueRouter from 'vue-router'

import Login from '../components/Login.vue'
import Index from '../components/Index.vue'
import Home from '../components/Home.vue'
import Seniority from '../components/Seniority.vue'
import Map from '../components/Map.vue'
import About from '../components/About.vue'

Vue.use(VueRouter)	

const routes = [
	{
		path: "/login",
		component: Login,
		children: []
	},
	{
		path: "/",
		redirect:"/home",
	},
	{
		path: "/index.html",
		redirect:"/home",
	},
	{
		path: "/index",
		component: Index,
		children: [
			{
				path: "/home",
				component: Home,
				children: []
			},
			{
				path: "/seniority",
				component: Seniority,
				children: []
			},
			{
				path: "/map",
				component: Map,
				children: []
			},
			{
				path: "/about",
				component: About,
				children: []
			},
		]
	}
	
]

const router = new VueRouter({
	routes
})
//挂载路由导航守卫
router.beforeEach((to, from, next) => {
	// to 将要访问
	//from 从哪访问
	//next 接着干 next(url) 重定向到url上 next() 继续访问to路径
	if(to.path =='/login' ){
		next();
	}
	let token = window.localStorage.getItem("mcsittoken")
	if (token=="" || token==null){
		return next("/login");
	}
	// if(from.path !=''){
	//    const userFlag = window.sessionStorage.getItem("user");
	//    if(!userFlag) return next("/login");
	// }  
	next();
})


export default router
